package com.Maykk.Demo02;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;

/**
 * @ClassName: Dmeo02
 * @Description: TODO 模拟斗地主发牌
 * @Author: MaykkStar@163.com
 */
public class Demo02 {
    public static void main(String[] args) {
        HashMap<Integer, String> card = new HashMap<>();
        ArrayList<Integer> cardList = new ArrayList<>();
        // 定义花色和点数
        String[] colors = {"♥", "♠", "♣", "♦"};
        String[] nums = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        // 将花色和点数放进牌盒
        int index = 0;
        for (String num : nums) {
            for (String color : colors) {
                card.put(index, color + num);
                cardList.add(index++);
            }
        } // 处理普通牌
        // 大小王单独处理
        card.put(index, "大");
        cardList.add(index++);
        card.put(index, "小");
        cardList.add(index);
        // 打乱排序
        // System.out.println(cardList);
        Collections.shuffle(cardList);
        // System.out.println(card);
        // 定义玩家
        TreeSet<Integer> player01 = new TreeSet<>();
        TreeSet<Integer> player02 = new TreeSet<>();
        TreeSet<Integer> player03 = new TreeSet<>();
        TreeSet<Integer> player04 = new TreeSet<>();
        // 发牌
        for (int i = 0; i < card.size(); i++) {
            if (i >= card.size() - 3) {
                player04.add(cardList.get(i));
            } else {
                switch (i % 3) {
                    case 0:
                        player01.add(cardList.get(i));
                        break;
                    case 1:
                        player02.add(cardList.get(i));
                        break;
                    case 2:
                        player03.add(cardList.get(i));
                        break;
                }
            }
        }
        // 看牌
        showCard("玩家1", player01, card);
        showCard("玩家2", player02, card);
        showCard("玩家3", player03, card);
        showCard("玩家4", player04, card);
    }

    private static void showCard(String name, TreeSet<Integer> ts, HashMap<Integer, String> card) {
        System.out.print(name + " : ");
        for (Integer key : ts) {
            System.out.print(card.get(key) + " ");
        }
        System.out.println("\n==============================================================");
    }
}
